<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!-- zTreeStyle.css -->
<link rel="stylesheet" type="text/css" href="${basePath}/css/zTreeStyle/zTreeStyle/zTreeStyle.css">
<!doctype html>
<html>
<head>
<style type="text/css">
	.ibox-content{
		border: none;
	}

</style>
</head>
<body class="gray-bg">
<div class="container creditbody">
	 <div class="iboxtitle">
	 	<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷后业务>待拖车列表</span>
    </div>
    <div class="ibox-content ibox-zxsearchqu ">
          <div class="row">
              <div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
               	   <label class="sr-only">客户名：</label>
                   <input type="text" placeholder="客户名" id="customerName" name="cusName" class="form-control" />
              </div>
              <div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
              		<div class="row">
              			<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">  
              				<input id="submitTimeStart" name="submitTimeStart" placeholder="开始时间" class="laydate-icon form-control" />
              			</div>
              			<label class="hxleft">至</label>
	                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">  
	                    	<input id="submitTimeEnd" name="submitTimeEnd" placeholder="结束时间" class="laydate-icon form-control" />
	                    </div>
                   </div>
               </div>
               <div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
               		<input type="hidden" id="orgCode" name="orgCode"/>
                   	<input type="text" id="unitName" name="unitName" class="form-control  smallicon" placeholder="双击选择地区"  ondblclick="unitNamecho()"/>
               </div>
	                     	
               <div class="col-xs-12 col-sm-12 col-md-2 col-lg-2">
              		<button class="zhixcx" type="button" onclick="query();">执行查询</button>
               </div>
          	</div>
          </div>
          <div class="ibox-content">
          		<button type="button" class="btn dpbtn_green" onclick="success();">拖车成功</button>
          		<button type="button" class="btn dpbtn_red" onclick="failed();">拖车失败</button>
          		<button type="button" class="btn dpbtn_blue" onclick="nodoit();">不处理</button>
          		<button type="button" class="btn dpbtn_green" onclick="exportExcel();">导出</button>
          		<button type="button" class="btn dpbtn_blue" onclick="trailerExcutor();">分配组别</button>
          </div>	
          <div class="ibox-content">	
	          	<div class="jqGrid_wrapper">
		             <table id="table_list_1"></table>
		             <div id="pager_list_1"></div>
	         	</div>
          </div>
      <div id="contractDiv"  style="display: none"> 
		 <div class="padding-nono"> 
			<table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table zxb-addtable">
				<tr>	
					<td align="right">
						<label class="control-label np">拖车时间：</label>
					</td>
					<td>
						<input id="tc_timeFail" class="laydate-icon form-control" onclick="laydate()"/>
					</td>
					<td align="right">
						<label class="control-label np">拖车地：</label>
					</td>
					<td>
					 	<input id="addrParkFail" type="text" class="form-control"/>
					</td>
				</tr>
				
				 <tr>
					<td align="right">
						<label class="control-label np">经办人：</label>
					</td>
					<td> 
						<input class="form-control" readonly="readonly" type="text" id="tcsb_operator" name="" value="${current_user_key.uname}">
					</td>
						
					<td align="right">
						<label class="control-label np">经办时间：</label>
					</td>
					<td>
						<input id="tcsb_operatorTime" placeholder="经办时间" class="laydate-icon form-control" onclick="laydate()">
					</td>
				</tr>
				<tr>
					<td align="right"  valign="top">
						<label class="control-label np">备注：</label>
					</td>
					<td colspan="3">
					 	<textarea id="remarkApply" class="form-control"></textarea>
					</td>
				</tr>	
			</div>
			</table>	 
			<table cellpadding="0" cellspacing="0" border="0"  width="100%">
				<tr>
					<td width="100%" align="center">
						 <div class="ibox-content">
				              <button class="btn dpbtn_green" type="button" onclick="tcsbsave();">提交</button>
				              <button class="btn dpbtn_red" type="button"  onclick="cancel();">取消</button>
				          </div>
					</td>
				</tr>
			</table>
		</div>
	</div>
	
	<div id="contractDivb"  style="display: none"> 
		 <div class="business-padding"> 
			<table cellpadding="0" cellspacing="0" border="0" class="tablefont">
				<tr>
					<td width="23%" align="right">
				    	<label class="col-sm-3 control-label np">执行组别：</label>
				    </td>
					<td width="77%">
						<div class="form-group">
		    				<div class="col-sm-8">
		    					<select id="TrailerExecutor" name="TrailerExecutor" class="select-control"></select>
		    				</div>
	    				</div>
					</td>	
				</tr>
			</table>
		</div>
		<div class="padding-nono"> 		 
			<table cellpadding="0" cellspacing="0" border="0"  width="100%">
				<tr>
					<td width="100%" align="center">
						 <div class="ibox-content">
				              <button class="btn dpbtn_green" type="button" onclick="fpzbsave();">提交</button>
				              <button class="btn dpbtn_red" type="button"  onclick="cancel();">取消</button>
				          </div>
					</td>
				</tr>
			</table>
		</div>
	</div>			
</div>		
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>

	<!-- jqGrid -->
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>	
    
    <!--zTreeStyle.js-->
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.core.js" charset="utf-8"></script>
	<script type="text/javascript" src="${basePath}/js/zTreeStyle/jquery.ztree.excheck.js" charset="utf-8"></script>
    
    <script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
    
    <script type="text/javascript">
	    
	    var winWidth = $(window).width();
		var winHeight = $(window).height();
		
	    jQuery(function($) { 
	    	laydate({
		        elem: '#submitTimeStart', 
		        event: 'focus' 
		    });
	    	laydate({
		        elem: '#submitTimeEnd', 
		        event: 'focus' 
		    });
	    	getData();
	    });
	    
	    var UpdateIndex; 
	    
	    function unitNamecho(){
	    	$.dpAjax({
	    		show:false,
	    		url:'${basePath}/BaseBusiUnitController/list',
	   			data:{},
	   			success: function(datas){
	    		  if(datas.flag == "100100")
				  {		  
	    			  var content = '<div class="ibox-content" style="height: 300px;border: 1px solid #F5F5F6; overflow:auto;overflow-x: hidden;">'
	    					+ '	<div id="treeDemo" class="ztree">&nbsp;</div>'
	     				+ '</div>'
	     				+ '<div class="ibox-content">'
	     				+ '	 <button class="btn dpbtn_green" type="button" onclick="oksave();">确定</button>'
	     				+ '	 <button class="btn dpbtn_red" type="button" onclick="cancel();">取消</button>'
	     				+ '</div>';
		     		
	    		    	UpdateIndex = layer.open({
	    			    	  title:'地区选择',
	    			    	  type: 1,
	    			    	  area: ['400px', '420px'], //宽高
	    			    	  content: content
	    			    });
	     		    	var setting = {
	     	 					check: {
	     	 						enable: false
	     	 					},
	     	 					data: {
	     	 						simpleData: {
	     	 							enable: true
	     	 						}
	     	 					}
	     	 			};
	    				  var  arr = [];
	    				  var d = datas.result.rows;
	    				  for(var i=0;i<d.length;i++)
	    				  {  
	    					  var r = d[i];
	    					  var objs = {};
	    					  objs.id = r.replaceId;
	    					  objs.pId = r.parentId;
	    					  objs.orgCode=r.orgCode;
	    					  objs.parentCode=r.parentCode;
	    					  objs.name = r.orgName;
	    					  arr.push(objs);
	    					  if(r.replaceId == 1){
		            		  	objs.open = true;
	     					  } else {
	     						objs.open = false; 
	     					  }
	    				  }  
	   				  $.fn.zTree.init($("#treeDemo"), setting, arr);
					  return;
				  }
				  if(datas.flag == "100200")
	                 {
					  $.fn.showDatas({"datas":datas});
	               	  return;
	                 }
				  layer.msg(datas.message, {icon: 2});
	               }
	    	});
	    }
	    
	    function oksave(){
	    	 var zTree = $.fn.zTree.getZTreeObj("treeDemo"); 
	    	 var node=zTree.getSelectedNodes();
	    	 var treeNode = node[0];
	    	 if(treeNode.id == 1) {
	    		 layer.msg('顶级父节点不可选择',{icon:7});
				 return;
	    	 }
	    	 document.getElementById('unitName').value=treeNode.name;
	    	 document.getElementById('orgCode').value=treeNode.orgCode;
	    	 layer.close(UpdateIndex); 
	    }	    
	    
	    function cancel(){
	    	 layer.closeAll(); 
	    }	
	    
	    var getData = function()
	    {
	  var winWidth = $('div.ibox-content').width();
	        winHeight = document.body.offsetHeight - 380;
	     	var win = winWidth / 7 - 20;
  	 	   $.jgrid.defaults.styleUI = 'Bootstrap';
  	 	   
		  jQuery("#table_list_1").jqGrid
		  ({
			url:'${basePath}/DhOverdueTrailerController/list',
	        datatype : "json",
	        postData:{"statusTrailer":10},
	        colNames : [ '主键','业务id','客户id','业务提交时间', '客户姓名','身份证号','当前逾期','拖车原因', '贷款额','业务部门','执行组别','执行组别'],
	        colModel : [ 
	                     {name: 'replaceId', index: 'id', hidden:true},
	                     {name: 'busiId', index: 'busiId', hidden:true},
	                     {name: 'cusId', index: 'cusId', hidden:true},
	                     {name: 'commitTime',index: 'commitTime',width: 170,align: "center",formatter:function(a,b,c){
	                       	 return formateStringDate(a);
	                     }},
	                     {name: 'cusName',index: 'cusName',width: 130,align: "center"},
	                  	 {name: 'customerNo',index: 'customerNo',width: 170,align: "center"},
	                  	 {name: 'amountRemainder',index: 'amountRemainder',width: 130,align: "center"},
	                  	 {name: 'typeTrailerDisplay',index: 'typeTrailer',width: 150,align: "center"},
	               		 {name: 'loanAmount',index: 'loanAmount',width: 130,align: "center"},
	               		 {name: 'unitName',index: 'unitName',width: 130,align: "center"},
	               	 	 {name: 'trailerExecutor', index: 'trailerExecutor', hidden:true},
	               	 	 {name: 'trailerExecutorDisplay', index: 'trailerExecutor',width: 130,align: "center"}
	                   ],
               mtype : "post",
   	           height: winHeight,
   	           width:winWidth,  
   	           autowidth: false,
              shrinkToFit: false,
              rowNum: 15,
              rowList: [15, 30, 45],
              viewrecords: true,
              pager: "#pager_list_1",
              hidegrid: false,
              multiselect : true,
              altRows:true,
              altclass:'someClass',
              ondblClickRow:function(rowId,v,e)
              {		
            	  
            	  var rowData = $("#table_list_1").jqGrid("getRowData", rowId);
            	  var customerNo = rowData.customerNo;
            	  var customerName = rowData.cusName;
            	  window.location.href="${basePath}/BaseCustomerViewController/customerDetail?customerNo=" + customerNo+"&customerName="+customerName;
              },
              jsonReader : {
            	  root:"result.rows",
            	  page: "result.page",
            	  total: "result.total",
            	  records: "result.records",
            	  repeatitems: false,
            	  id: "id"
              },
              loadComplete:function(datas){
            	  if (datas.flag == "100100") {
                      layer.msg("查询成功!", {icon: 6, time: 1000});
                      return;
                  }
            	  if(datas.flag == '100802') {
    				  top.location.href = thisLoginUrl;
    				  return;
    			  }

            	  layer.msg(datas.message, {icon: 2});
              }
	      });
	    }	    
	    
	    window.onresize = function()
	    {
	    	$("#table_list_1").setGridWidth($(window).width()-80);
	    }
	    
	    var exportExcel=function(){
	    	var count = $("#table_list_1").jqGrid("getGridParam", "records");
	    	if(count == 0 || count == "")
	    	{  
	    		layer.msg("表中无数据，无法导出！", {icon: 5});
				return;
	    	}
	    	
	    	var customerName = document.getElementById('customerName').value || '';
	    	var submitTimeStart=$("#submitTimeStart").val();
	    	var submitTimeEnd=$("#submitTimeEnd").val();
	    	var orgCode=$("#orgCode").val();
	    	window.location.href="${basePath}/DhOverdueTrailerController/exportExcel?customerName="+customerName+"&submitTimeStart="+submitTimeStart+"&submitTimeEnd="+submitTimeEnd+"&orgCode="+orgCode;
	    }
	    
	    var query = function(dayEnum)
	    {
	    	var postData = $("#table_list_1").jqGrid("getGridParam", "postData");
	    	var data = {};
	    	data.cusName = document.getElementById('customerName').value || '';
	    	data.submitTimeStart=$("#submitTimeStart").val();
	    	data.submitTimeEnd=$("#submitTimeEnd").val();
	    	data.unitCode=$("#orgCode").val();
	    	$.extend(postData, data);
	    	refresh();
	    }
	    
	    var refresh = function()
	    {
	    	$("#table_list_1").jqGrid("setGridParam", { search: true }).trigger("reloadGrid", [{ page: 1}]);
	    }
	    
		//拖车成功
		var success=function(){
			var rowData = jQuery('#table_list_1').jqGrid('getGridParam','selarrrow');  
			var uid = $('#table_list_1').jqGrid('getGridParam','selarrrow').join(",");
	        var rowDatab = $("#table_list_1").jqGrid("getRowData", uid);
		    var busiId=rowDatab.busiId;
		    var cusId=rowDatab.cusId;
		    var id=rowDatab.replaceId;
	    	if(rowData.length < 1)
	    	{  
	    		layer.msg("请选择一个用户！", {icon: 5});
				return;
	    	}
	    	
	    	if(rowData.length > 1)
	    	{
	    		layer.msg("只能选择一个用户！", {icon: 5});
				return;
	    	}
			window.location.href="trailerHandlingSuccess.jsp?busiId="+busiId+"&cusId="+cusId+"&id="+id;   
	    }
		
		//拖车失败
		function failed(){
			var rowData = jQuery('#table_list_1').jqGrid('getGridParam','selarrrow');  
	    	if(rowData.length < 1)
	    	{  
	    		layer.msg("请选择一个用户！", {icon: 5});
				return;
	    	}
	    	
	    	if(rowData.length > 1)
	    	{
	    		layer.msg("只能选择一个用户！", {icon: 5});
				return;
	    	}
			layer.open({
				  title:'拖车失败记录',
				  type: 1,
				  area: ['550px', '400px'], //宽高
				  content: $('#contractDiv')
			});
		}
		
		//拖车失败保存
		var tcsbsave = function(){
			var uid = $('#table_list_1').jqGrid('getGridParam','selarrrow').join(",");
	        var rowDatab = $("#table_list_1").jqGrid("getRowData", uid);
		    var busiId=rowDatab.busiId;
		    var cusId=rowDatab.cusId;
		    var id=rowDatab.replaceId;
		    var data={};
		    data.creatorName=$("#tcsb_operator").val();
           	data.jbDate=$("#tcsb_operatorTime").val();
           	data.creator="${current_user_key.id}";
           	data.busiId= busiId;
	    	data.cusId=cusId;
	    	data.id=id;
	    	data.trailerId=id;
           	//拖车失败参数
       		data.timeTrailer=$("#tc_timeFail").val();
       		data.addrPark=$("#addrParkFail").val();
       		data.remarkApply=$("#remarkApply").val();
       		data.statusTrailer=30;
			$.dpAjax({
	    		url:'${basePath}/DhOverdueTrailerRecordController/save',
	    		data:data,
    			success: function(datas){
	    			if(datas.flag == "100100"){
						  layer.msg('执行成功！', {icon: 6});
						  refresh();
						  return;
					}
					if(datas.flag == "100200"){
						$.fn.showDatas({"datas":datas});
	                	return;
	                }
                 }
			});	
			layer.closeAll();
		}
		
		//拖车失败取消
		var cancel = function(){
			layer.closeAll();
		}
		
		//不处理
		var nodoit = function(){
			var rowData = jQuery('#table_list_1').jqGrid('getGridParam','selarrrow');  
	    	if(rowData.length < 1)
	    	{  
	    		layer.msg("请选择一个用户！", {icon: 5});
				return;
	    	}
	    	
	    	if(rowData.length > 1)
	    	{
	    		layer.msg("只能选择一个用户！", {icon: 5});
				return;
	    	}
			layer.confirm('确定放弃处理该客户？',{
				  title:'拖车申请处理',
				  btn: ['确认','取消'] //按钮
				}, function(){
					layer.closeAll();
					var data={};
					var uid = $('#table_list_1').jqGrid('getGridParam','selarrrow').join(",");
			        var rowDatab = $("#table_list_1").jqGrid("getRowData", uid);
					data.statusTrailer=40;
					data.id=rowDatab.replaceId;
					$.dpAjax({
			    		url:'${basePath}/DhOverdueTrailerController/modify',
			    		data:data,
		    			success: function(datas){
			    			if(datas.flag == "100100"){
								  layer.msg('执行成功！', {icon: 6});
								  refresh();
								  return;
							}
							if(datas.flag == "100200"){
								$.fn.showDatas({"datas":datas});
			                	return;
			                }
		                 }
					});
				},function(){
					layer.closeAll();
				});
	    }
		
		//执行组别
		var zxzblayer;
		
		function trailerExcutor(){
			var rowData = jQuery('#table_list_1').jqGrid('getGridParam','selarrrow');  
	    	if(rowData.length < 1)
	    	{  
	    		layer.msg("请至少选择一个客户！", {icon: 5});
				return;
	    	}
	    	
			$.dpAjax({
		    	url:'${basePath}/DataDictionaryController/getEnableList',
		    	
				data:{
					"parentValue":"TrailerExecutor"
				},
				success: function(datas){
					  if(datas.flag == "100100")
						  {
		 					  var result = datas.result.rows;
		 					  var programme_sel=[];
		 				      for(var i=0;i<result.length;i++){
		 				          var programme = result[i];
		 				          programme_sel.push('<option value="'+programme.value+'">'+programme.name+'</option>')
		 				      }
		 				      $("#TrailerExecutor").html(programme_sel.join(' '));
							  return;
						  }
						  if(datas.flag == "100200")
		                  {
							  $.fn.showDatas({"datas":datas});
		                	  return;
		                  }
						  layer.msg(datas.message, {icon: 2});
	             }
		    });
			zxzblayer=layer.open({
				  title:'拖车执行组别',
				  type: 1,
				  area: ['350px', '250px'], //宽高
				  content: $('#contractDivb')
			});
		}
		
		var fpzbsave=function(){
			var ids = $("#table_list_1").jqGrid("getGridParam", "selarrrow"); 
			var id = "";	
			for(var i=0;i<ids.length;i++){
			  rowData = $("#table_list_1").jqGrid('getRowData',ids[i]);
			  id += rowData.replaceId + ',';
			}
			var data={};
			data.id=id;
           	data.trailerExecutor=$("#TrailerExecutor").val();
			$.dpAjax({
	    		url:'${basePath}/DhOverdueTrailerController/update',
	    		data:data,
    			success: function(datas){
	    			if(datas.flag == "100100"){
						  layer.close(zxzblayer);
						  refresh();
						  return;
					}
					if(datas.flag == "100200"){
						$.fn.showDatas({"datas":datas});
	                	return;
	                }
                 }
			});
		} 
		
		var formateStringDate=function(sDate1){
	    	if(!sDate1 || sDate1 == ''){
	    		return '-';
	    	}
	    	var aDate  =  sDate1.substring(0,sDate1.lastIndexOf(":"));
	    	return aDate;
	    }
    </script>
</body>
</html>

